<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>角色仓库权限设置</title>
    <script type="text/javascript">

      var roleWarehouseDS;

      //处理权限锁定
      function lockRoleWarehouseFn(id){
        Ext.Ajax.request({
          url : '/privilege/roleWarehouseLock',
          success : function (result, request) {
            roleWarehouseDS.load();
          },
          failure : function (result, request){
            Ext.MessageBox.show({
              title: '消息',
              msg: "通讯失败，请从新操作",
              buttons: Ext.MessageBox.OK,
              icon: Ext.MessageBox.WARNING
            });
          },
          method : 'GET',
          params : {
            id : id
          }
        });
      }

      //处理角色
      function lockRoleWarehouseFn(id){
        Ext.Ajax.request({
          url : '/admin/roleWarehouseLock',
          success : function (result, request) {
            roleWarehouseDS.load();
          },
          failure : function (result, request){
            Ext.MessageBox.show({
              title: '消息',
              msg: "通讯失败，请从新操作",
              buttons: Ext.MessageBox.OK,
              icon: Ext.MessageBox.WARNING
            });
          },
          method : 'GET',
          params : {
            id : id
          }
        });
      }

      Ext.onReady(function(){
        //-----------------角色Grid----------------------------
          roleWarehouseDS = Ext.create('Ext.data.Store', {
              //autoDestroy : true,
              model : 'RoleWarehouse',
              proxy : {
                  type : 'ajax',
                  url: '/admin/getRoleWarehouse?role_id=<%=params[:role_id]%>',
                  reader : {
                      type : 'json',
                      root : 'root',
                      totalProperty : 'totalProperty'// 数据集记录总数
                  }
              },
              autoLoad:true
          });


        //锁定角色
        function renderRoleWarehouseIsLucked(value, cellmeta, record, index, columnIndex, store){
          if (record.get("is_locked")=="1"){
            return "<a style=cursor:pointer onclick=lockRoleWarehouseFn(" + store.getAt(index).get('id')+")><em style=color:red>锁定</em></a>";
          }else{
            return "<a style=cursor:pointer onclick=lockRoleWarehouseFn(" + store.getAt(index).get('id')+")><em style=color:green >未锁定</em></a>";
          }
        }

        var roleGrid = Ext.create('Ext.grid.Panel', {
          title:'角色仓库列表',
          store: roleWarehouseDS,
          columns : [Ext.create('Ext.grid.RowNumberer'),
              {
                  header: '是否锁定',
                  dataIndex: 'is_locked',
                  renderer: renderRoleWarehouseIsLucked,
                  width: 60
              },{
                  header: '仓库名称',
                  dataIndex: 'warehouse_name',
                  width: 190
              }],
          width: 325,
          height: 365,
          frame: true,
          loadMask: true
        });
        
        roleGrid.render("role_warehouse_workbanch");
      })
    </script>
  </head>
  <body>
    <div id="role_warehouse_workbanch"></div>
  </body>
</html>
